package com.aerospace.serviceprovider.socket;

import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;

public class SocketClient {
    public static final String IP = "127.0.0.1";
    public static final int PORT = 9999;
    public static void main(String[] args) {
        SocketClient.start();
    }

    public static void start() {
        try {
            Socket s = new Socket(IP, PORT);
            DataOutputStream ps = new DataOutputStream(s.getOutputStream());
            DataInputStream dis = new DataInputStream(new BufferedInputStream(s
                    .getInputStream()));


            String clientMessage = "呼叫服务端请建立Socket链接";
            System.out.println("Socket 客户端执行!!!!");
            ps.writeUTF(clientMessage);
            ps.flush();
            System.out.println("--------------");
            System.out.println(dis.readUTF().toString());

            while(!dis.readUTF().isEmpty()){
                System.out.println("服务器返回的信息====》》》》" + dis.readUTF());
            }
            while (true){
//            dis.close();
//            ps.close();
//                System.out.println("客户端待机");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
